<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/webjars/bootstrap/4.5.2/css/bootstrap.css}">
</head>
<body>

<div>
    <form th:action="@{/emp}" method="post">
        <!--
            发送put请求：
            1. SpringMVC中配置HiddenHttpMethodFilter;(SpringBoot自动配置好的)
            2. 页面建立一个post表单
            3.创建一个input项，name="_method";值是我们请求方法
        -->
        <input type="hidden" name="_method" value="PUT" th:if="${emp!=null}"/>

        <input type="hidden" name="id" th:value="${emp.id}" th:if="${emp!=null}">

        <div class="form-group">
            <span>LastName</span><br>
            <input type="text" name="lastName" class="form-control" th:value="${emp!=null} ? ${emp.lastName}">
        </div>

        <div class="form-group">
            <span>Email</span><br>
            <input type="email" name="email" class="form-control" th:value="${emp!=null} ? ${emp.email}">
        </div>

        <div class="form-group">
            <span>Gender</span><br>
            <div class="form-check">
                <input type="radio" name="gender" value="0" class="form-check-input" th:checked="${emp!=null} ? ${emp.gender==0}">
                <label class="form-check-label">男</label>
            </div>
            <div class="form-check">
                <input type="radio" name="gender" value="1" class="form-check-input" th:checked="${emp!=null} ? ${emp.gender==1}">
                <label class="form-check-label">女</label>
            </div>
        </div>

        <div class="form-group">
            <label>department</label>
            <select class="form-control" name="department.id">
                <option th:each="dept : ${depts}" th:value="${dept.id}" th:selected="${emp!=null} ? ${dept.id == emp.department.id}">
                    [[${dept.departmentName}]]
                </option>
            </select>
        </div>

        <div class="form-group">
            <span>Birth(yyyy-MM-dd)</span><br>
            <input type="text" name="birth" class="form-control" th:value="${emp!=null}?${#dates.format(emp.birth, 'yyyy-MM-dd HH:mm:ss')}">
        </div>

        <input type="submit" th:value="${emp!=null}? 修改:添加" class="btn btn-success">
    </form>
</div>

</body>
</html>